;(MisumiGuideBushingPlanMakeTop 16.0 20.0 26.0 3 25 20 "SGBBH" "MBSH" 15 70 45 20 "06M")

;(MisumiGuideBushingPlanMakeBottom 16 20 26 3 25 20 "SGBBH" "MBSH" 15)

; radius, lead angle, u, head thickness, head diameter plus, la la la, b b

;(MisumiGuidePinProfileMake 16.0 2.0 15 3 5 7 80 50 20)

;(MisumiBallCageProfileMake (getpoint) (/ pi 2) 16 20 25)

(command "OPENDCL")

(defun C:GP ()
  (if (dcl_project_load "MisumiBallBearingSubliners.odcl" T)
    (progn
      (setq #MisumiBallBearingSublinersPostDiaList '(13 16 20 25))
      (if (null #MisumiBallBearingSublinersPostDiaNth) (setq #MisumiBallBearingSublinersPostDiaNth 1))
      (if (null #MisumiBallBearingSublinersViews) (setq #MisumiBallBearingSublinersViews "Profile"))
      (if (null #MisumiBallBearingSublinersBushingLength) (setq #MisumiBallBearingSublinersBushingLength "BL2"))
      (if (null #MisumiBallBearingSublinersBushingStyle) (setq #MisumiBallBearingSublinersBushingStyle "SGBBS"))
      (if (null #MisumiBallBearingSublinersCageLength) (setq #MisumiBallBearingSublinersCageLength "CL2"))
      (if (null #MisumiBallBearingSublinersCageStyle) (setq #MisumiBallBearingSublinersCageStyle "MBSH"))
      (if (null #MisumiBallBearingSublinersPinLA) (setq #MisumiBallBearingSublinersPinLA "LA1"))
 
      (setq result (dcl_form_show MisumiBallBearingSubliners_Form1))
    )
    (alert "MisumiBallBearingSubliners.odcl not found!")
  )
  (princ)
)

(defun c:MisumiBallBearingSubliners/Form1#OnInitialize (/)
  (princ "\nInitializing the form...")
  (dcl_SlideView_load MisumiBallBearingSubliners_Form1_SlideView1 (findfile (strcat "MisumiBallBearingSubliners" #MisumiBallBearingSublinersViews ".sld")) nil)
  (dcl-OptionList-SetCurSel MisumiBallBearingSubliners/Form1/postDiameterOptionList #MisumiBallBearingSublinersPostDiaNth)
  (princ "\nDone.")
)

(defun c:MisumiBallBearingSubliners/Form1/Xray#OnClicked ( val /)
  (princ "\nInitializing the Xray clicked...")
  (dcl_SlideView_load MisumiBallBearingSubliners_Form1_SlideView1 (findfile (strcat "MisumiBallBearingSubliners" (setq #MisumiBallBearingSublinersViews "Xray") ".sld")) nil)
)

(defun c:MisumiBallBearingSubliners/Form1/Top#OnClicked ( val /)
  (princ "\nInitializing the Top clicked...")
  (dcl_SlideView_load MisumiBallBearingSubliners_Form1_SlideView1 (findfile (strcat "MisumiBallBearingSubliners" (setq #MisumiBallBearingSublinersViews "Top") ".sld")) nil)
)

(defun c:MisumiBallBearingSubliners/Form1/Bottom#OnClicked ( val /)
  (princ "\nInitializing the Bottom clicked...")
  (dcl_SlideView_load MisumiBallBearingSubliners_Form1_SlideView1 (findfile (strcat "MisumiBallBearingSubliners" (setq #MisumiBallBearingSublinersViews "Bottom") ".sld")) nil)
)

(defun c:MisumiBallBearingSubliners/Form1/Profile#OnClicked ( val /)
  (princ "\nInitializing the Profile clicked...")
  (dcl_SlideView_load MisumiBallBearingSubliners_Form1_SlideView1 (findfile (strcat "MisumiBallBearingSubliners" (setq #MisumiBallBearingSublinersViews "Profile") ".sld")) nil)
)


(defun c:MisumiBallBearingSubliners/Form1/postDiameterOptionList#OnSelChanged (index value /)
  (setq #MisumiBallBearingSublinersPostDiaNth index)
  (princ (itoa index))
)


(defun c:MisumiBallBearingSubliners/Form1/cmdCancel#OnClicked (/)
  (princ "\nCancel clicked...")
  (dcl-Form-Close MisumiBallBearingSubliners/Form1)
)
(defun c:MisumiBallBearingSubliners/Form1/OK#OnClicked (/)
  (princ "\nOK clicked...")
  (dcl-Form-Close MisumiBallBearingSubliners/Form1)
  (MisumiGuideBushingPlanMakeTop 16.0 20.0 26.0 3 25 20 "SGBBH" "MBSH" 15 70 45 20 "06M")
)


(defun MisumiBallCageProfileMake (p1 ang pinDiameter bushingId cageLength / perAng oppAng ballDiameter p2 revAng p3 p4 p5 p6 p7 p8 p1a p1b p1c p1d p2a p2b p2c p2d p3a p3b p4a p4b p5a p5b p6a p6b p7a p7b p6a p8b)
  (setq perAng (- ang (/ pi 2))
        oppAng (- perAng pi)
        ballDiameter (/ (- bushingId pinDiameter) 2)
        p2 (polar p1 ang cageLength)
        revAng (angle p2 p1)
        p3 (polar p1 ang (/ ballDiameter 2))
        p4 (polar p1 ang (+ ballDiameter (/ ballDiameter 2)))
        p5 (polar p1 ang (+ (* ballDiameter 2) (/ ballDiameter 2)))
        p6 (polar p2 revAng (/ ballDiameter 2))
        p7 (polar p2 revAng (+ ballDiameter (/ ballDiameter 2)))
        p8 (polar p2 revAng (+ (* ballDiameter 2) (/ ballDiameter 2)))
        p1a (polar p1 perAng (/ bushingId 2))
        p1b (polar p1 perAng (/ pinDiameter 2))
        p1c (polar p1 oppAng (/ pinDiameter 2))
        p1d (polar p1 oppAng (/ bushingId 2))
        p2a (polar p2 perAng (/ bushingId 2))
        p2b (polar p2 perAng (/ pinDiameter 2))
        p2c (polar p2 oppAng (/ pinDiameter 2))
        p2d (polar p2 oppAng (/ bushingId 2))
        p3a (polar p3 perAng (+ (/ pinDiameter 2) (/ ballDiameter 2)))
        p3b (polar p3 oppAng (+ (/ pinDiameter 2) (/ ballDiameter 2)))
        p4a (polar p4 perAng (+ (/ pinDiameter 2) (/ ballDiameter 2)))
        p4b (polar p4 oppAng (+ (/ pinDiameter 2) (/ ballDiameter 2)))
        p5a (polar p5 perAng (+ (/ pinDiameter 2) (/ ballDiameter 2)))
        p5b (polar p5 oppAng (+ (/ pinDiameter 2) (/ ballDiameter 2)))
        p6a (polar p6 perAng (+ (/ pinDiameter 2) (/ ballDiameter 2)))
        p6b (polar p6 oppAng (+ (/ pinDiameter 2) (/ ballDiameter 2)))
        p7a (polar p7 perAng (+ (/ pinDiameter 2) (/ ballDiameter 2)))
        p7b (polar p7 oppAng (+ (/ pinDiameter 2) (/ ballDiameter 2)))
        p8a (polar p8 perAng (+ (/ pinDiameter 2) (/ ballDiameter 2)))
        p8b (polar p8 oppAng (+ (/ pinDiameter 2) (/ ballDiameter 2)))

  )
  (linemake (list p1a p1b p2b p2a p1a) "A03_HOLES")
  (linemake (list p1c p1d p2d p2c p1c) "A03_HOLES")
  (CircleMake p3a (/ ballDiameter 2) "A03_HOLES")
  (CircleMake p3b (/ ballDiameter 2) "A03_HOLES")
  (CircleMake p4a (/ ballDiameter 2) "A03_HOLES")
  (CircleMake p4b (/ ballDiameter 2) "A03_HOLES")
  (CircleMake p5a (/ ballDiameter 2) "A03_HOLES")
  (CircleMake p5b (/ ballDiameter 2) "A03_HOLES")
  (CircleMake p6a (/ ballDiameter 2) "A03_HOLES")
  (CircleMake p6b (/ ballDiameter 2) "A03_HOLES")
  (CircleMake p7a (/ ballDiameter 2) "A03_HOLES")
  (CircleMake p7b (/ ballDiameter 2) "A03_HOLES")
  (CircleMake p8a (/ ballDiameter 2) "A03_HOLES")
  (CircleMake p8b (/ ballDiameter 2) "A03_HOLES")


  (princ)
)
;(MisumiStopperProfileMake (getpoint) (/ pi 2) 15. 17.3 15. 3.) SHCS (point dir cbore typ size len
(defun MisumiStopperProfileMake (p1 ang id od len head / p2 p3 perAng oppAng p1a p1b p2a p2b p2c p2d p3a p3b p3c p3d)
  (setq p2 (polar p1 ang len)
        p3 (polar p1 ang (+ len head))
        perAng (- ang (/ pi 2))
        oppAng (- perAng pi)
        p1a (polar p1 perAng (/ id 2))
        p1b (polar p1 oppAng (/ id 2))
        p2a (polar p2 perAng (/ od 2))
        p2b (polar p2 perAng (/ id 2))
        p2c (polar p2 oppAng (/ id 2))
        p2d (polar p2 oppAng (/ od 2))
        p3a (polar p3 perAng (/ od 2))
        p3b (polar p3 perAng (/ id 2))
        p3c (polar p3 oppAng (/ id 2))
        p3d (polar p3 oppAng (/ od 2))
  )        ;setq
  (linemake (list p2b p1a p1b p2c) "A01_RAILS")
  (linemake (list p2a p2d p3d p3a p2a) "A01_RAILS")
  (SHCS p3 (angle p2 p1) "Yes" "SH" "06M" 20)

  (princ)
)
;(MisumiBushingProfileMake (getpoint) (/ pi 2) 20 26 25 3)
(defun MisumiBushingProfileMake (p1 ang id od len head / p2 p3 p1a p1b p1c p1d p2a p2b p2c p2d p3a p3b p3c p3d)
  (setq perAng (- ang (/ pi 2))
        oppAng (- perAng pi)
  )        ;setq
  (if head
    (progn
      (setq p2 (polar p1 ang head)
            p3 (polar p1 ang len)
            p1a (polar p1 perAng (+ 1.5 (/ od 2)))
            p1b (polar p1 perAng (/ id 2))
            p1c (polar p1 oppAng (/ id 2))
            p1d (polar p1 oppAng (+ 1.5 (/ od 2)))
            p2a (polar p2 perAng (+ 1.5 (/ od 2)))
            p2b (polar p2 perAng (/ od 2))
            p2c (polar p2 oppAng (/ od 2))
            p2d (polar p2 oppAng (+ 1.5 (/ od 2)))
            p3a (polar p3 perAng (/ od 2))
            p3b (polar p3 perAng (/ id 2))
            p3c (polar p3 oppAng (/ id 2))
            p3d (polar p3 oppAng (/ od 2))
            p3ba (polar p3b (+ ang pi) len)
            p3ca (polar p3c (+ ang pi) len)
      )
      (linemake (list p1b p3b) "A03_HOLES")
      (linemake (list p1c p3c) "A03_HOLES")
      (linemake (list p1b p1a p2a p2b p3a p3b) "A03_HOLES")
      (linemake (list p1c p1d p2d p2c p3d p3c) "A03_HOLES")
    )
    (progn
      (setq p2 (polar p1 ang len)
            p1a (polar p1 perAng (/ od 2))
            p1b (polar p1 perAng (/ id 2))
            p1c (polar p1 oppAng (/ id 2))
            p1d (polar p1 oppAng (/ od 2))
            p2a (polar p2 perAng (/ od 2))
            p2b (polar p2 perAng (/ id 2))
            p2c (polar p2 oppAng (/ id 2))
            p2d (polar p2 oppAng (/ od 2))
      )
      (linemake (list p1b p1a p2a p2b p1b) "A03_HOLES")
      (linemake (list p1c p1d p2d p2c p1c) "A03_HOLES")
    )
  )
  (princ)
)

(defun MisumiGuidePinProfileMake (pinDiameter radius leadAngle uDistance headThickness headDiameterPlus la lb b / p1 t2 t3 ang perAng oppAng tanDist p2 p3 p4 p5 p6 p7 p1a p1b p1c p1d p5a p5b p5c p5d p2a p2b p3a p3b p4a p4b p6a p6b p7a p7b)
  (setq p1 (place)
        t2 (upoint 1 "" "\nInsertion point of bottom bushing: " nil p1)
        t3 (udist 1 "" "\nInsertion point of top bushing: " nil p1)
        ang (angle p1 t2)
        perAng (- ang (/ pi 2))
        oppAng (- perAng pi)
        tanDist (* uDistance (vle-tan (dtr leadAngle)))
        p2 (polar p1 ang b)
        p3 (polar p1 ang (- la uDistance))
        p4 (polar p1 ang la)
        p5 (polar p1 (angle t2 p1) headThickness)
        p6 (polar p1 (angle t2 p1) (- lb uDistance))
        p7 (polar p1 (angle t2 p1) lb)
        p1a (polar p1 perAng (+ (/ pinDiameter 2) (/ headDiameterPlus 2)))
        p1d (polar p1 oppAng (+ (/ pinDiameter 2) (/ headDiameterPlus 2)))
        p1b (polar p1 perAng (/ pinDiameter 2))
        p1c (polar p1 oppAng (/ pinDiameter 2))
        p5a (polar p5 perAng (+ (/ pinDiameter 2) (/ headDiameterPlus 2)))
        p5d (polar p5 oppAng (+ (/ pinDiameter 2) (/ headDiameterPlus 2)))
        p5b (polar p5 perAng (/ pinDiameter 2))
        p5c (polar p5 oppAng (/ pinDiameter 2))
        p2a (polar p2 perAng (/ pinDiameter 2))
        p2b (polar p2 oppAng (/ pinDiameter 2))
        p3a (polar p3 perAng (/ pinDiameter 2))
        p3b (polar p3 oppAng (/ pinDiameter 2))
        p4a (polar p4 perAng (- (/ pinDiameter 2) tanDist))
        p4b (polar p4 oppAng (- (/ pinDiameter 2) tanDist))
        p6a (polar p6 perAng (/ pinDiameter 2))
        p6b (polar p6 oppAng (/ pinDiameter 2))
        p7a (polar p7 perAng (- (/ pinDiameter 2) tanDist))
        p7b (polar p7 oppAng (- (/ pinDiameter 2) tanDist))
  )        ;setq

  ;(setq 37.5dist (* (vle-tan (dtr 37.5)) radius))


  (linemake (list p1a p1d p5d p5a p1a) "A03_HOLES")
  (linemake (list p1b p3a p4a p4b p3b p1c) "A03_HOLES")
  (linemake (list p5b p6a p7a p7b p6b p5c) "A03_HOLES")
  (linemake (list p2a p2b) "A03_HOLES")

  (princ)
)

(defun MisumiGuideBushingPlanMakeTop (PinDiameter id od HeadDiameterInc BushingLength BallCageLength BushingType BallCageType StopperLength LA LB B thread / p1 name touchcmd tdat BallBearingDiameter ScrewSize ScrewLength)
  (setq p1 (place)
        name (strcat BushingType " " (rtos PinDiameter) "-" (itoa BushingLength) " " BallCageType " " (itoa BallCageLength) " SSTK " (itoa StopperLength) " " (itoa LA) " " (itoa LB) " " (itoa B))
        touchcmd (strcat "(MisumiGuideBushingPlanMakeTop " (rtos PinDiameter) " " (rtos id) " " (rtos od) " " (itoa HeadDiameterInc) " " (itoa BushingLength) " " (itoa BallCageLength) " \"" BushingType "\" \"" BallCageType "\" " (itoa StopperLength) " " (itoa LA) " " (itoa LB) " " (itoa B) " \"" thread "\")")
    tdat (if (= HeadDiameterInc 0)
           (strcat "(HOLE 0" (rtos (/ od *unitinversion*) 2 4) " \" (Wring Fit, Loctite)\"" ")")
           (strcat "(CB 0" (rtos (/ od *unitinversion*) 2 4) " " (rtos (/ (+ 1 HeadDiameterInc od) *unitinversion*) 2 4) " " (rtos (/ 3.4 *unitinversion*) 2 4) " \" (Wring Fit, Loctite)\" T)")
         )
    BallBearingDiameter (/ (- id PinDiameter) 2)
    ScrewSize (vle-string-split "x" thread)
    ScrewLength (cadr ScrewSize)
    ScrewSize (car ScrewSize)
  )        ;setq
  (if (not (tblsearch "BLOCK" name))
    (progn
      (entmake (list (cons 0 "BLOCK")
                     (cons 2 name)
                     (cons 70 0)
                     (cons 10 '(0.0 0.0 0.0))
               )
      )
      (if (> HeadDiameterInc 0)
        (entmake (list (cons 0 "CIRCLE")
                       (cons 8 "LINE_HIDDENX1")
                       (cons 10 '(0.0 0.0 0.0))
                       (cons 40 (/ (+ HeadDiameterInc od) 2))
                 )
        )
      )
      (entmake (list (cons 0 "CIRCLE")
                     (cons 8 "LINE_HIDDENX1")
                     (cons 10 '(0.0 0.0 0.0))
                     (cons 40 (/ od 2))
               )
      )
      (entmake (list (cons 0 "CIRCLE")
                     (cons 8 "A03_HOLES")
                     (cons 10 '(0.0 0.0 0.0))
                     (cons 40 (/ id 2))
               )
      )
      (entmake (list (cons 0 "CIRCLE")
                     (cons 8 "A03_HOLES")
                     (cons 10 '(0.0 0.0 0.0))
                     (cons 40 (/ PinDiameter 2))
               )
      )
      (entmake (list (cons 0 "CIRCLE")
                     (cons 8 "A03_HOLES")
                     (cons 10 (list (+ (/ PinDiameter 2) (/ BallBearingDiameter 2)) 0.0 0.0))
                     (cons 40 (/ BallBearingDiameter 2))
               )
      )
      (entmake (list (cons 0 "CIRCLE")
                     (cons 8 "A03_HOLES")
                     (cons 10 (list (- (+ (/ PinDiameter 2) (/ BallBearingDiameter 2))) 0.0 0.0))
                     (cons 40 (/ BallBearingDiameter 2))
               )
      )
      (entmake (list (cons 0 "CIRCLE")
                     (cons 8 "A03_HOLES")
                     (cons 10 (list 0.0 (+ (/ PinDiameter 2) (/ BallBearingDiameter 2)) 0.0))
                     (cons 40 (/ BallBearingDiameter 2))
               )
      )
      (entmake (list (cons 0 "CIRCLE")
                     (cons 8 "A03_HOLES")
                     (cons 10 (list 0.0 (- (+ (/ PinDiameter 2) (/ BallBearingDiameter 2))) 0.0))
                     (cons 40 (/ BallBearingDiameter 2))
               )
      )
      ;(MAINSCRW '(0.0 0.0 0.0) ScrewSize "SH" "1" ScrewLength)
      (if (> HeadDiameterInc 0)
        (centers '(0.0 0.0 0.0) (+ HeadDiameterInc od))
        (centers '(0.0 0.0 0.0) od)
      )
      (entmake '((0 . "ENDBLK")))
    )      ;progn
  )        ;if
  (entmake (list (cons 0 "INSERT")
                 (cons 2 name)
                 (cons 8 "A03_HOLES")
                 (cons 10 p1)
                 (list -3 (list "TOUCH_CMD" (cons 1000 touchcmd))
                       (list "OBJ_TRANSFORM" (cons 1000 tdat))
                       (list "OBJ_GROUP"
                             (cons 1002 "{")
                             (cons 1000 (strcat "Guide Pin, Cat.#SGPWH " (itoa (fix PinDiameter)) "-" (itoa LA) "-" (itoa LB) "-" (itoa B)))
                             (cons 1000 "Misumi")
                             (cons 1002 "}")
                             (cons 1002 "{")
                             (cons 1000 (strcat "Bushing, Cat.#" BushingType " " (itoa (fix PinDiameter)) "-" (itoa BushingLength)))
                             (cons 1000 "Misumi")
                             (cons 1002 "}")
                             (cons 1002 "{")
                             (cons 1000 (strcat "Cage, Cat.#" BallCageType " " (itoa (fix PinDiameter)) "-" (itoa BallCageLength)))
                             (cons 1000 "Misumi")
                             (cons 1002 "}")
                             (cons 1002 "{")
                             (cons 1000 (strcat "Stopper, Cat.#SSTK " (itoa (fix PinDiameter)) "-" (itoa StopperLength)))
                             (cons 1000 "Misumi")
                             (cons 1002 "}")
                       )
                 )
           )
  )
  (princ)
)

(defun MisumiGuideBushingPlanMakeBottom (PinDiameter id od HeadDiameterInc BushingLength BallCageLength BushingType BallCageType StopperLength / p1 name touchcmd tdat BallBearingDiameter)
  (setq p1 (place)
        name (strcat BushingType " " (rtos PinDiameter) "-" (itoa BushingLength) " " BallCageType " " (itoa BallCageLength) " SSTK " (itoa StopperLength))
        touchcmd (strcat "(MisumiGuideBushingPlanMakeBottom " (rtos PinDiameter) " " (rtos id) " " (rtos od) " " (itoa HeadDiameterInc) " " (itoa BushingLength) " " (itoa BallCageLength) " \"" BushingType "\" \"" BallCageType "\" " (itoa StopperLength) ")")
    tdat (if (= HeadDiameterInc 0)
           (strcat "(HOLE 0" (rtos (/ od *unitinversion*) 2 4) " \" (Wring Fit, Loctite)\"" ")")
           (strcat "(CB 0" (rtos (/ od *unitinversion*) 2 4) " " (rtos (/ (+ 1 HeadDiameterInc od) *unitinversion*) 2 4) " " (rtos (/ 3.4 *unitinversion*) 2 4) " \" (Wring Fit, Loctite)\" T)")
         )
    BallBearingDiameter (/ (- id PinDiameter) 2)
  )        ;setq
  (if (not (tblsearch "BLOCK" name))
    (progn
      (entmake (list (cons 0 "BLOCK")
                     (cons 2 name)
                     (cons 70 0)
                     (cons 10 '(0.0 0.0 0.0))
               )
      )
      (if (> HeadDiameterInc 0)
        (entmake (list (cons 0 "CIRCLE")
                       (cons 8 "LINE_HIDDENX1")
                       (cons 10 '(0.0 0.0 0.0))
                       (cons 40 (/ (+ HeadDiameterInc od) 2))
                 )
        )
      )
      (entmake (list (cons 0 "CIRCLE")
                     (cons 8 "A03_HOLES")
                     (cons 10 '(0.0 0.0 0.0))
                     (cons 40 (/ od 2))
               )
      )
      (entmake (list (cons 0 "CIRCLE")
                     (cons 8 "A03_HOLES")
                     (cons 10 '(0.0 0.0 0.0))
                     (cons 40 (/ id 2))
               )
      )
      (entmake (list (cons 0 "CIRCLE")
                     (cons 8 "A03_HOLES")
                     (cons 10 '(0.0 0.0 0.0))
                     (cons 40 (/ PinDiameter 2))
               )
      )
      (entmake (list (cons 0 "CIRCLE")
                     (cons 8 "A03_HOLES")
                     (cons 10 (list (+ (/ PinDiameter 2) (/ BallBearingDiameter 2)) 0.0 0.0))
                     (cons 40 (/ BallBearingDiameter 2))
               )
      )
      (entmake (list (cons 0 "CIRCLE")
                     (cons 8 "A03_HOLES")
                     (cons 10 (list (- (+ (/ PinDiameter 2) (/ BallBearingDiameter 2))) 0.0 0.0))
                     (cons 40 (/ BallBearingDiameter 2))
               )
      )
      (entmake (list (cons 0 "CIRCLE")
                     (cons 8 "A03_HOLES")
                     (cons 10 (list 0.0 (+ (/ PinDiameter 2) (/ BallBearingDiameter 2)) 0.0))
                     (cons 40 (/ BallBearingDiameter 2))
               )
      )
      (entmake (list (cons 0 "CIRCLE")
                     (cons 8 "A03_HOLES")
                     (cons 10 (list 0.0 (- (+ (/ PinDiameter 2) (/ BallBearingDiameter 2))) 0.0))
                     (cons 40 (/ BallBearingDiameter 2))
               )
      )
      (if (> HeadDiameterInc 0)
        (centers '(0.0 0.0 0.0) (+ HeadDiameterInc od))
        (centers '(0.0 0.0 0.0) od)
      )
      (entmake '((0 . "ENDBLK")))
    )      ;progn
  )        ;if
  (entmake (list (cons 0 "INSERT")
                 (cons 2 name)
                 (cons 8 "A03_HOLES")
                 (cons 10 p1)
                 (list -3 (list "TOUCH_CMD" (cons 1000 touchcmd))
                       (list "OBJ_TRANSFORM" (cons 1000 tdat))
                       (list "OBJ_GROUP"
                             (cons 1002 "{")
                             (cons 1000 (strcat "Bushing, Cat.#" BushingType " " (itoa (fix PinDiameter)) "-" (itoa BushingLength)))
                             (cons 1000 "Misumi")
                             (cons 1002 "}")
                             (cons 1002 "{")
                             (cons 1000 (strcat "Cage, Cat.#" BallCageType " " (itoa (fix PinDiameter)) "-" (itoa BallCageLength)))
                             (cons 1000 "Misumi")
                             (cons 1002 "}")
                             (cons 1002 "{")
                             (cons 1000 (strcat "Stopper, Cat.#SSTK " (itoa (fix PinDiameter)) "-" (itoa StopperLength)))
                             (cons 1000 "Misumi")
                             (cons 1002 "}")
                       )
                 )
           )
  )
  (princ)
)


(defun MisumiBallBearingSublinersUpdate (typ val)
  (cond
    ((= typ "Post")
     (MisumiSGPWH val)
    )))
(defun MisumiSGBBW (dia)
  (cond
    ((= dia 13.) '(17. 24. 0 30 35))  ;id, od, head dia, lengths
    ((= dia 16.) '(20. 28. 0 35 40))
    ((= dia 20.) '(26. 34. 0 40 45 50))
    ((= dia 25.) '(31. 40. 0 45 50 60))
  )
)

(defun MisumiSGBBS (dia)
  (cond
    ((= dia 13.) '(17. 22. 0 20 25 30))
    ((= dia 16.) '(20. 26. 0 25 30 35))
    ((= dia 20.) '(26. 31. 0 25 30 35 40))
    ((= dia 25.) '(31. 37. 0 35 40))
  )
)

(defun MisumiSGBBH (dia)
  (cond
    ((= dia 13.) '(17. 22. 3 20 25 30))
    ((= dia 16.) '(20. 26. 3 25 30 35))
    ((= dia 20.) '(26. 31. 3 25 30 35 40))
    ((= dia 25.) '(31. 37. 3 35 40))
  )
)

(defun MisumiMBSH (dia)
  (cond
    ((= dia 13.) '(2 25 30 35))       ;dia, lengths
    ((= dia 16.) '(2 30 35 40))
    ((= dia 20.) '(3 30 35 40 45))
    ((= dia 25.) '(3 35 40 45 50))
  )
)

(defun MisumiMBJH (dia)
  (cond
    ((= dia 13.) '(2 25 30 35))
    ((= dia 16.) '(2 30 35 40))
    ((= dia 20.) '(3 30 35 40 45))
    ((= dia 25.) '(3 35 40 45 50))
  )
)

(defun MisumiSGPWH (dia)
  (cond
    ((= dia 13.) '(1.5 15 2 5 7 60 70 80 10 30))  ; radius, lead angle, u, head thickness, head diameter plus, la la la, b b
    ((= dia 16.) '(2.0 15 3 5 7 70 80 90 10 30))
    ((= dia 20.) '(2.0 15 3 5 7 80 90 100 10 30))
    ((= dia 25.) '(3.0 15 4 5 7 90 100 110 10 30))
  )
)

(defun MisumiSGPWH-LB (dia la)
  (cond
    ((and (= dia 13.) (= la 60)) '(30 50))        ; LB length 10mm inc.
    ((and (= dia 13.) (= la 70)) '(30 60))
    ((and (= dia 13.) (= la 80)) '(40 60))
    ((and (= dia 16.) (= la 70)) '(30 60))
    ((and (= dia 16.) (= la 80)) '(30 70))
    ((and (= dia 16.) (= la 90)) '(40 80))
    ((and (= dia 20.) (= la 80)) '(40 70))
    ((and (= dia 20.) (= la 90)) '(40 70))
    ((and (= dia 20.) (= la 100)) '(50 80))
    ((and (= dia 25.) (= la 90)) '(50 70))
    ((and (= dia 25.) (= la 100)) '(50 80))
    ((and (= dia 25.) (= la 110)) '(60 90))

  )
)

(defun MisumiSSTK (dia)
  (cond
    ((= dia 13) '(15.0 12 3 10 20))  ; od, step dia, head thickness, s s 1mm inc.
    ((= dia 16) '(17.3 15 3 10 20))
    ((= dia 20) '(24.0 19 3 11 25))
    ((= dia 25) '(29.0 24 3 11 30))
  )
)

(defun MisumiSSTK-SHCS (dia s)
  (cond
    ((and (= dia 13) (<= 13 s)) "05Mx15")
    ((and (= dia 13) (<= 18 s)) "05Mx20")
    ((and (= dia 13) (<= 23 s)) "05Mx25")
    ((and (= dia 16) (<= 13 s)) "06Mx15")
    ((and (= dia 16) (<= 18 s)) "06Mx20")
    ((and (= dia 16) (<= 23 s)) "06Mx25")
    ((and (= dia 20) (<= 13 s)) "08Mx15")
    ((and (= dia 20) (<= 18 s)) "08Mx20")
    ((and (= dia 20) (<= 23 s)) "08Mx25")
    ((and (= dia 20) (<= 28 s)) "08Mx25")
    ((and (= dia 25) (<= 13 s)) "08Mx15")
    ((and (= dia 25) (<= 18 s)) "08Mx20")
    ((and (= dia 25) (<= 23 s)) "08Mx25")
    ((and (= dia 25) (<= 28 s)) "08Mx30")
    ((and (= dia 25) (<= 30 s)) "08Mx35")
  )
)
